<template>
    <div>
        <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: '/order_list' }">运单列表</el-breadcrumb-item>
        <el-breadcrumb-item>添加运单</el-breadcrumb-item>
        </el-breadcrumb><br>
        <center>
            <div style="width:300px;border:solid 1px gray;padding:20px;margin-top:120px;border-radius:20px">
                <el-form label-width="80px" class="demo-ruleForm" v-if="create_table">
                    <center><p>添加运单</p></center>
                    <el-form-item label='发货单号'>
                        <el-input placeholder='请输入发货单号' v-model="order_number"></el-input>
                    </el-form-item>
                    <el-form-item label="客户信息">
                        <el-select v-model="customer" placeholder="请选择">
                        <el-option v-for="(item,index) in customer_list" :key="index" :label="item.username" :value="index"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="货物类型 :">
                        <el-select v-model="goods_type" placeholder="请选择">
                        <el-option v-for="(item,index) in goods_type_list" :key="index" :label="item.name" :value="index"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="order_created">添加</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </center>
    </div>
        
</template>
<script>
import {get_customer_list_get,get_goods_type_list_get,get_create_order_get} from './axios_api/api.js'
export default {
    data(){
        return {
            create_table: true,
            order_number: '',
            customer: '',
            customer_list: [],
            
            goods_type: '',
            goods_type_list: []
        }
    },
    mounted() {
        this.get_customer_list()
        this.get_goods_type_list()
    },
    methods: {
        
        get_goods_type_list() {
            get_goods_type_list_get().then(res => {
                this.goods_type_list = res.goods_type_list
            })
        },
        get_customer_list(){
            get_customer_list_get().then(res => {
                console.log(res)
                this.customer_list = res.customer_list
            })
        },
        order_created() {
            // # 发货单号
            // invoice
            // # 下单的客户信息
            // belongs
            // # 用户名
            // username
            // # 联系人
            // contacts
            // # 联系电话
            // phone
            // # 公司地址
            // address
            // # 货物类型
            // goods_type_name
            // # 延迟开始
            // delayed
            // # 记录间隔
            // interval
            // # 安全温度
            // safe_temperature
            // # 报警事件
            // alert
            // # 运单状态
            // order_state
            // # 温度记录
            // temperature_record
            // # 结束时间
            // end_time
            let goods_type = this.goods_type_list[this.goods_type]
            console.log(goods_type);
            let goods_type_name = goods_type.name,delayed = goods_type.delayed,interval = goods_type.interval,safe_temperature = goods_type.min_temperature + '' + '~' + goods_type.max_temperature,alert=goods_type.alert,order_state='等待发货',temperature_record='正常';
            let user_msg = this.customer_list[this.customer];
            let username=user_msg.username,contacts=user_msg.contacts,phone=user_msg.phone,address=user_msg.address;
            get_create_order_get({
                order_number:this.order_number,
                username:username,
                contacts:contacts,
                phone:phone,
                address:address,
                goods_type_name:goods_type_name,
                delayed:delayed,
                interval:interval,
                safe_temperature:safe_temperature,
                alert:alert,
                order_state:order_state,
                temperature_record:temperature_record,
                }).then(res => {
                    console.log(res)
                })


            
        }
    }
}
</script>